import Layout from '@/layouts/index.vue'
import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
import { setPermissions } from './permissions'

const baseRoutes: Array<RouteRecordRaw> = [
  {
    path: '/login',
    name: 'Login',
    component: import('@/views/login/index.vue')
  }
]

const menusRoutes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'HomeMenu',
    component: Layout,
    redirect: '/home',
    meta: {
      title: '首页',
      icons: 'home'
    },
    children: [
      {
        path: '/home',
        component: () => import('@/views/home/home/index.vue'),
        name: 'Home',
        meta: { title: '首页', icons: 'home' }
      },
      {
        path: '/board',
        component: () => import('@/views/home/board/index.vue'),
        name: 'Board',
        meta: { title: '看板', icons: 'board' }
      }
    ]
  },
  {
    path: '/component',
    name: 'ComponentMenu',
    component: Layout,
    meta: {
      title: '组件',
      icons: 'component'
    },
    children: [
      {
        path: '/table',
        component: () => import('@/views/component/table/index.vue'),
        name: 'Table',
        meta: { title: '表格', icons: 'component-table' }
      },
      {
        path: '/form',
        component: () => import('@/views/component/form/index.vue'),
        name: 'Form',
        meta: { title: '表单', icons: 'component-form' }
      }
    ]
  },
  {
    path: '/:pathMatch(.*)*',
    name: 'NotFound',
    component: () => import('@/views/error/notFound/index.vue')
  }
]

const routes = [...baseRoutes, ...menusRoutes]
const router = createRouter({
  history: createWebHashHistory(),
  routes
})

setPermissions(router)

export { menusRoutes }

export default router
